package trabalhopmforçadesenha;

public class PasswordChecker01 {

    public void checkPassword(String passwd){
        int is = 0;
        String res = "weak";
        String text = "";

        if (passwd.length()<5)
        {
            is = (is+3);
            text   = text + "3 points for length (" + passwd.length() + ")\n";
        }
        else if (passwd.length()>5 && passwd.length()<8)
        {
            is = (is+6);
            text   = text + "6 points for length (" + passwd.length() + ")\n";
        }
        else if (passwd.length()>7 && passwd.length()<16)
        {
            is = (is+12);
            text   = text + "12 points for length (" + passwd.length() + ")\n";
        }
        else if (passwd.length()>16)
        {
            is = (is+18);
            text   = text + "18 point for length (" + passwd.length() + ")\n";
        }

        for (char a : passwd.toCharArray())
        {
            if (Character.isLetter(a)) {
                if (Character.isLowerCase(a))
                {
                    is = (is+1);
                    text   = text + "1 point for at least one lower case char\n";
                    break;
                }
            }
        }

        for (char a : passwd.toCharArray())
        {
            if (Character.isLetter(a)) {
                if (Character.isUpperCase(a))
                {
                    is = (is+5);
                    text   = text + "5 points for at least one upper case char\n";
                    break;
                }
            }
        }


        for (char a : passwd.toCharArray())
        {
            if (Character.isDigit(a))
            {
                is = (is+5);
                text   = text + "5 points for at least one number\n";
                break;
            }
        }

        int cont = 0;
        for (int i = 0; i < passwd.length(); i++)
        {
           if (Character.isDigit(passwd.charAt(i))){
            cont++;
           }
        }
        
        if (cont >=3)
        {
            is = (is+5);
            text   = text + "5 points for at least three numbers\n";
        }
        
        char simbs[] = new char[11];
        simbs[0] = '!';
        simbs[1] = '@';
        simbs[2] = '#';
        simbs[3] = '$';
        simbs[4] = '%';
        simbs[5] = '^';
        simbs[6] = '&';
        simbs[7] = '*';
        simbs[8] = '?';
        simbs[9] = '_';
        simbs[10] = '~';
        
        int contSimbs = 0;
        
        for (int i = 0; i < passwd.length(); i++)
        {
            for (int j = 0; j < simbs.length; j++)
            {
                if (passwd.charAt(i) == simbs[j])
                {
                    contSimbs++;
                }
            }
        }

        if (contSimbs >= 1)
        {
            is = (is+5);
            text   = text + "5 points for at least one special char\n";
        }

        if (contSimbs >= 2)
        {
            is = (is+5);
            text   = text + "5 points for at least two special chars\n";
        }
        
        boolean lower = false;
        boolean upper = false;
        
        for (int i = 0; i < passwd.length(); i++)
        {
            if (Character.isLowerCase(passwd.charAt(i)))
            {
                lower = true;
            }
            
            if (Character.isUpperCase(passwd.charAt(i)))
            {
                upper = true;
            }
        }
        
        if ( lower && upper)
        {
            is = (is+2);
            text   = text + "2 combo points for upper and lower letters\n";
        }
        
        boolean number = false;
        for (int i = 0; i < passwd.length(); i++)
        {
            if (Character.isDigit(passwd.charAt(i))){
                number = true;
            }
        }
        
        if ( (lower || upper) && number)
        {
            is = (is+2);
            text   = text + "2 combo points for letters and numbers\n";
        }
        
        if ((cont > 0 || lower || upper) && contSimbs > 0)
        {
            is = (is+2);
            text   = text + "2 combo points for (letters or numbers) and special chars\n";
        }
        
        if(is < 16)
        {
           res = "very weak";
        }
        else if (is > 15 && is < 25)
        {
           res = "weak";
        }
        else if (is > 24 && is < 35)
        {
           res = "medium";
        }
        else if (is > 34 && is < 45)
        {
           res = "strong";
        }
        else
        {
           res = "stronger";
        }

	System.out.println("Strength score is: " + is);
        System.out.println("Strength verdict: " + res);
        System.out.println("Log: " + text);
    }
}
